	********************************************************************************
	****
	**** Date: 04.25.2022							 
	**** Update: 07.12.2023					 
	**** Author: JW josephgwright@gmail.com 				 	
	**** NOTE: This program has been executed in Stata 18.0	 
	**** 
	**** Using files in $dir: 
	****
	****  	pers-use.dta
	****
	*********************************************************************************
		capture log close
		log using Ch7.log, replace

	******************************
	**** Set directory, seed *****
	******************************
		set more off 
		set matsize 1000
		global seed ="984353"
		set scheme plotplain
		cd "$dir"

		***********************************
		**** Party leader funding trends ****
		*************************************
		use pers-use,clear
		gen pubfin = l1v2elpubfin_ord==3 | l1v2elpubfin_ord==4 if l1v2elpubfin_ord~=.
		qui sum v2pafunds_6
		local m = r(mean)
		twoway (lpoly v2pafunds_6 year,lpat(solid)ylab(.1(.02).2)yline(`m',lcol(red)) legend(off) ///
			ytit(Share of leaders who fund their own party)xtit(Year)xlab(1990(5)2020))
		gr export "$dir\golden\T-Rising-Leader-Funding.pdf",as(pdf)replace 
		table period, stat(min year)  stat(max year) stat(mean v2pafunds_6)  nformat(%5.2f)
		
		/*
period  |                                                   
  1     |        1991.00         1995.00                0.13
  2     |        1996.00         2000.00                0.16
  3     |        2001.00         2005.00                0.17
  4     |        2006.00         2010.00                0.17
  5     |        2011.00         2015.00                0.19
  6     |        2016.00         2020.00                0.19
		*/ 
 		ttest v2pafunds_6 if year==min,by(create)
		ttest pubfin if year==min,by(create)
		reg create v2pafunds_6 if year==min,cluster(cowcode)
		reg create pubfin if year==min,cluster(cowcode)

		************************************************************************************
		*** Publicly financed campaigns reduce likelihood of personalist party selection ***
		************************************************************************************
		use pers-use,clear
		table year,stat(n l1v2smpardom)
		gen pubfin = l1v2elpubfin_ord==3 | l1v2elpubfin_ord==4 if l1v2elpubfin_ord~=. & l1v2elpubfin_ord~=2
		gen proportional= v2elparlel==1 | v2elparlel==3
 		qui gen wealth=e_migdppcln
		qui xi:reg e_migdppcln i.cowcode i.year 
		qui predict hat
		replace wealth=hat if wealth==.
		hist wealth
		sum wealth e_migdppcln
		gen time =(year-1990)/10
		keep if year==min
		
		local var = "ivdem ld l1polar l1supdem ipi wealth"
		foreach v of local var {
			qui sum `v'
			qui replace `v'=(`v'-r(mean))/(r(sd))
		}
		replace wealth= wealth/.5
		graph bar persparty,over(pubfin) 
		
		global d="pubfin"
		global c="ld ivdem l1polar ipi wealth"
		
		* Reduces selection into Create party *
		ttest create,by(pubfin)
		reg create $d,cluster(lid)
		reghdfe create $d,a(cowcode year)cluster(lid)
		reg create $d $c,cluster(lid)
		reghdfe create $d $c,a(cowcode year)cluster(lid)
		
		* Public financing of election reduces selection in party personalism *
		centile persparty if pubfin~=.,centile(50)
		local c = r(c_1)
		gen hipers = persparty>`c' if persparty~=.
		ttest hipers,by(pubfin)
		
		reg persparty $d,cluster(lid)
		reghdfe persparty $d,a(cowcode year)cluster(lid)
		reg persparty $d $c,cluster(lid)
		est store fin1
		reghdfe persparty $d $c,a(cowcode year)cluster(lid)
		est store fin2

		label var ld `""Democracy" "age      " "'
		label var ivdem `""Democracy" "level     ""'
		label var $d `""{bf:Publicly}   " "{bf:financed}  " "{bf:campaigns}""'
		label var l1polar "Polarization"
		label var ipi  `""Party  " "system " "instit.  ""'
		label var wealth "GDP pc"
		label var time "Time trend"

		coefplot (fin1, msymbol(T))  (fin2, msymbol(D))   , ///
			drop(_cons) order(pubfin) ///
			grid(glcolor(gs15))xline(0,lpattern(dash)) xlab(-.2(.1)0.1) ///
			xtitle(Coefficient estimates)  level(95 90) title("Publicly financed campaigns", ///
			size(medium)height(6))subtit("reduce selection into personalist ruling party",size(vsmall))xsize(2) ysize(3.5) mlabel format(%9.2g) ///
			mlabsize(vsmall)mlabposition(2)mlabgap(*.65)legend(lab(3 "Pooled")  lab(6 "Within") ///
			size(vsmall)order(3 6)pos(5)col(1)ring(0)) ///
			note("One observation per each of 482 leaders in 82 countries",size(vsmall)pos(6)) 
		gr export "$dir\golden\T-Public-financing-pers-party.pdf",as(pdf)replace 
		
 
 *************** The END *****************
		
		log close
